Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rocksdb overhaul and clean up #4730

Merged
merged 9 commits into from
Sep 25, 2024

Conversation

RickiNano
Copy link
Contributor

The main scope of this PR is to clean up and simplify the RocksDb implementation. It also aims to rely mostly on RocksDb default options instead of hardcoded values
I recommend reading this PR commit by commit.

Read cache and write cache is now set in the config file, and they both defaults to RocksDb's recommended values
Read cache can be configured 1-1024MB and defaults to 32MB per table
Write cache can be configured 1-256MB and defaults to 64MB per table
Previously block_cache (read cache) was from 8MB and up, depending on which table and the value of Memory_multiplier.

All Column families are now using the same options for simplicity.

Several hardcoded options have been removed and the default RocksDb value is now used. Here is a list of the options with the old hardcoded value and the new RocksDb default.

Database options

Key name Current value New value Comment
max_total_wal_size 1GB 0 0 means dynamic
memtable_whole_key_filtering true false
max_manifest_file_size 100MB 1GB
compaction_pri kMinOverlappingRatio kMinOverlappingRatio
enable_pipelined_write true false
max_file_opening_threads -1 16 If max_open_files is -1, DB will open all files on DB::Open()

ColumnFamily options

Key name Current value New value Comment
max_bytes_for_level_multiplier 8 10
max_write_buffer_size_to_maintain 16MB 0 DEPRECATED
ttl 1 day 30 days
target_file_size_multiplier 10 1 1 means files in different levels will have similar size
target_file_size_base 32MB 64MB
write_buffer_size 32MB 64MB Configurable. Config default 64MB. RocksDb default also 64MB
max_write_buffer_number 2 2
max_write_buffer_size_to_maintain 16-48MB 0

Table options

Key name Current value New value Comment
format_version 4 5 See notes below
block_cache 8-64MB 32MB Read cache per table
block_size 16MB 0 0 means RocksDb is autocalculating size

Data format version:
The current data storage format version is 4 but this PR changes it to the latest version 5.
Version 5 introduces enhancements and optimizations, particularly around prefix iterators and performance improvements in how RocksDB handles certain read operations. Version 5 retains compatibility with data created using version 4. Only new data is written in version 5. No data migration is needed

Compression:
Changing compression mode to kSnappyCompression will reduce ledger size and disk utilization. However, from my testing the total compression rate was less than 5% so I recommend that we continue using uncompressed storage.

Initial testing:
I have tested this PR on an existing live RocksDb ledger for 7+ days 24/7. I have also bootstrapped a live ledger from scratch.
I have tested with maximum cache settings on a 16GB system. 8 GB was used after 48 hours and was not increasing.
My current PR node (NanoTicker) is now running on this version with RocksDb.
All testing was done on Windows.

Further improvements:
The existing implementation uses a tombstone map containing deleted entries. It also creates an event listener that flushes tombstones on delete. I don't see any point in doing this. RocksDb can handle tombstones internally. There is a comment claiming that too many tombstones can affect read performance.
Without the code that handles tombstone mapping it still runs fine (including on loads of deletes). I did not see any change in performance from this.
I decided to leave the tombstone handling as is, since I'm not certain if it may be needed in some special cases.

Resources:
https://betterprogramming.pub/navigating-the-minefield-of-rocksdb-configuration-options-246af1e1d3f9
https://github.com/facebook/rocksdb/wiki

@clemahieu clemahieu merged commit 0d7b1de into nanocurrency:develop Sep 25, 2024
22 of 28 checks passed
@qwahzi qwahzi added this to the V28 milestone Sep 25, 2024
@qwahzi qwahzi added the database Relates to lmdb or rocksdb label Sep 27, 2024
RickiNano added a commit to RickiNano/nano-node that referenced this pull request Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Relates to lmdb or rocksdb
Projects
Status: Merged / V28.0
Development

Successfully merging this pull request may close these issues.

3 participants